<template>
  <div>
    <h2>百知教育学生管理系统</h2>
    <router-link to="/ems">用户管理</router-link>
    <router-link to="/add">添加</router-link>
    <hr>
    <table border="2" width="100%" >
      <tr>
        <td>ID</td>
        <td>姓名</td>
        <td>年龄</td>
        <td>生日</td>
        <td>地址</td>
        <td>操作</td>
      </tr>
      <tr v-for="ems in emss" :key="ems.id">
        <td>{{ems.id}}</td>
        <td>{{ems.name}}</td>
        <td>{{ems.age}}</td>
        <td>{{ems.bir}}</td>
        <td>{{ems.address}}</td>
        <td><a href="javascript:;" @click="delEms(ems.id)">删除</a>|<router-link :to="`/update/${ems.id}`">修改</router-link> </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: "Ems",
  data() {
    return {
      emss: {}
    }
  },
  methods: {
      //获取用户列表
      get_ems() {
      this.$axios.get("http://localhost:8989/ems/findAllEms").then(res => {
        console.log(res.data);
        this.emss = res.data
        })
      },
      //删除
      delEms(id) {
      this.$axios.get("http://localhost:8989/ems/deleteEms?id=" + id).then(res => {
        console.log(res.data);
        this.get_ems();
        }).catch(error => {
        console.log("删除成功");
        })
     },
    created() {
      this.get_ems()
    }
  }
}
</script>

<style scoped>

</style>
